﻿<%@ WebHandler Language="C#" Class="Login" %>

using System;
using System.Web;
using Newtonsoft.Json;
using System.Data;
using Common;
public class Login : IHttpHandler
{

    public void ProcessRequest(HttpContext context)
    {
        context.Response.Charset = "UTF-8";
        context.Response.ContentType = "text/plain";

        string strResult = "";
        string where = "";
        DataTable dtResult = new DataTable();
        ReturnMsg rm = new ReturnMsg();
        rm.retcode = 4;
        rm.remark = "登陆错误!";
        string action = context.Request.QueryString["action"];
        string userid = context.Request.QueryString["userid"] != null ? context.Request.QueryString["userid"] : "";
        string userpwd = context.Request.QueryString["userpwd"] != null ? context.Request.QueryString["userpwd"] : "";
        string username = context.Request.QueryString["username"] != null ? context.Request.QueryString["username"] : "";
        string workshop = context.Request.QueryString["workshop"] != null ? context.Request.QueryString["workshop"] : "";
        switch (action)
        {
            case "login":
                //DataSet ds = new BLL.pe_paperMa().GetList(0, "createTime>'" + DateTime.Now.AddMonths(-1).ToString("yyyy-MM-dd HH:mm:ss") + "'", " createTime desc");
                where = string.Format("[EmployeeId]='{0}' and [Password]='{1}' ", userid, userpwd);
                DataSet  ds = new BLL.T_PublicEmployee().GetList(0, where, " EmployeeId desc");
                if (ds != null)
                    if (ds.Tables.Count > 0)
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            rm.retcode = 0;
                            rm.remark = "登陆成功！";
                            //rm.retdatatable = ds.Tables[0];
                            rm.retdatatable = null;
                            rm.retjson = ds.Tables[0].Rows[0]["EmployeeName"].ToString();
                        }
                        else
                        {
                            rm.retcode = 1;
                            rm.remark = "用户名或密码错误！";
                            rm.retdatatable = null;
                            rm.retjson = "";
                        }
                break;
            case "reguser":
                where = string.Format("[EmployeeId]='{0}' ", userid, userpwd);
                DataSet dsr = new BLL.T_PublicEmployee().GetList(0, where, " EmployeeId desc");
                if (dsr != null)
                    if(dsr.Tables.Count>0)
                        if (dsr.Tables[0].Rows.Count > 0)
                        {
                            rm.retcode = 2;
                            rm.remark = "用户ID重复！";
                            break;
                        }
                Model.T_PublicEmployee t_PublicEmployee = new Model.T_PublicEmployee();
                t_PublicEmployee.EmployeeId = userid;
                t_PublicEmployee.EmployeeName = username;
                t_PublicEmployee.Password = userpwd;
                t_PublicEmployee.WorkShop = workshop;
                long count= new  BLL.T_PublicEmployee().Add(t_PublicEmployee);
                if (count > 0)
                {
                    rm.retcode = 3;
                    rm.remark = "注册成功！";
                    rm.retdatatable = null;
                    rm.retjson = "";
                    break;
                }
                break;
        }

        strResult = rm.retdata;
        context.Response.Write(strResult);
        context.Response.End();

    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

}